package com.aaa.mbs.service.impl;

import com.aaa.mbs.dao.AccountStatementMapper;
import com.aaa.mbs.entity.AccountStatement;
import com.aaa.mbs.service.AccountStatementService;
import com.aaa.mbs.service.MemberService;
import com.aaa.mbs.vo.LoginLogShow;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author: Bug Maker
 * @date: 2021/2/23 18:31
 * @description:
 */
@Service
public class AccountStatementServiceImpl implements AccountStatementService {
    @Autowired
    private AccountStatementMapper accountStatementMapper;

    @Autowired
    private MemberService memberService;
    @Override
    public List<AccountStatement> selectIncomeShow(String yearMonth) {
        return accountStatementMapper.selectIncomeShow(yearMonth);
    }

    @Override
    public List<LoginLogShow> selectLoginLog(String yearMonth) {
        return accountStatementMapper.selectLoginLog(yearMonth);
    }

    /**
     * 功能描述:用户充值添加订单，修改余额
     * @param accountStatement accountStatement
     * @return com.aaa.common.util.Result<com.aaa.mbs.entity.AccountStatement>
     */
    @Override
    public AccountStatement addMoney(AccountStatement accountStatement) {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        String date2=sdf.format(date);
        accountStatement.setAddtime(date2);
        this.accountStatementMapper.insertSelective(accountStatement);
        this.memberService.updateAccount(accountStatement.getMemberId(),accountStatement.getAmount());
        return accountStatement;
    }
}
